<template>
  <div id="app" class="wrapper wrapper-content animated fadeInRight v-cloak" v-cloak>
    <div class="row">
      <div class="col-md-12">
        <form id="examineResultForm" method="post" class="form m-t" @submit.prevent="save()" accept-charset="UTF-8">
          <input type="hidden" name="id" v-model="item.id"/>
          <input type="hidden" name="token" v-model="item.token"/>
          <input type="hidden" name="newFlag" v-model="newFlag"/>
          <div class="clearfix "></div>
          <div class="col-md-6">

            <div class="form-group clearfix">
              <label class="col-md-8 control-label">考核指标ID：</label>
              <div class="col-md-12">
                <input id="bean-targetId" name="targetId" v-model="item.targetId" class="form-control" type="text"
                    placeholder="请输入考核指标ID" required="" aria-required="true" aria-describedby="bean-targetId-error"
                    aria-invalid="true">
                <span id="bean-targetId-error" class="help-block m-b-none" for="bean-targetId"></span>
              </div>
            </div>

            <div class="form-group clearfix">
              <label class="col-md-8 control-label">被评人ID：</label>
              <div class="col-md-12">
                <input id="bean-userId" name="userId" v-model="item.userId" class="form-control" type="text"
                    placeholder="请输入被评人ID" required="" aria-required="true" aria-describedby="bean-userId-error"
                    aria-invalid="true">
                <span id="bean-userId-error" class="help-block m-b-none" for="bean-userId"></span>
              </div>
            </div>

            <div class="form-group clearfix">
              <label class="col-md-8 control-label">被评人姓名：</label>
              <div class="col-md-12">
                <input id="bean-userName" name="userName" v-model="item.userName" class="form-control" type="text"
                    placeholder="请输入被评人姓名" required="" aria-required="true" aria-describedby="bean-userName-error"
                    maxlength="32" aria-invalid="true">
                <span id="bean-userName-error" class="help-block m-b-none" for="bean-userName"></span>
              </div>
            </div>

            <div class="form-group clearfix">
              <label class="col-md-8 control-label">总分：</label>
              <div class="col-md-12">
                <input id="bean-totalScore" name="totalScore" v-model="item.totalScore" class="form-control" type="text"
                    placeholder="请输入总分" required="" aria-required="true" aria-describedby="bean-totalScore-error"
                    aria-invalid="true">
                <span id="bean-totalScore-error" class="help-block m-b-none" for="bean-totalScore"></span>
              </div>
            </div>

            <div class="form-group clearfix">
              <label class="col-md-8 control-label">系统自动评分：</label>
              <div class="col-md-12">
                <input id="bean-autoScore" name="autoScore" v-model="item.autoScore" class="form-control" type="text"
                    placeholder="请输入系统自动评分" required="" aria-required="true" aria-describedby="bean-autoScore-error"
                    aria-invalid="true">
                <span id="bean-autoScore-error" class="help-block m-b-none" for="bean-autoScore"></span>
              </div>
            </div>

          </div>
          <div class="col-md-6">

            <div class="form-group clearfix">
              <label class="col-md-8 control-label">自评分：</label>
              <div class="col-md-12">
                <input id="bean-selfScore" name="selfScore" v-model="item.selfScore" class="form-control" type="text"
                    placeholder="请输入自评分" required="" aria-required="true" aria-describedby="bean-selfScore-error"
                    aria-invalid="true">
                <span id="bean-selfScore-error" class="help-block m-b-none" for="bean-selfScore"></span>
              </div>
            </div>

            <div class="form-group clearfix">
              <label class="col-md-8 control-label">上级评分：</label>
              <div class="col-md-12">
                <input id="bean-leaderScore" name="leaderScore" v-model="item.leaderScore" class="form-control"
                    type="text" placeholder="请输入上级评分" required="" aria-required="true"
                    aria-describedby="bean-leaderScore-error" aria-invalid="true">
                <span id="bean-leaderScore-error" class="help-block m-b-none" for="bean-leaderScore"></span>
              </div>
            </div>

            <div class="form-group clearfix">
              <label class="col-md-8 control-label">备注：</label>
              <div class="col-md-12">
                <input id="bean-memo" name="memo" v-model="item.memo" class="form-control" type="text"
                    placeholder="请输入备注" aria-describedby="bean-memo-error" maxlength="255" aria-invalid="true">
                <span id="bean-memo-error" class="help-block m-b-none" for="bean-memo"></span>
              </div>
            </div>

          </div>

          <div class="clearfix "></div>
          <div class="col-12 text-center" style="height: 50px;">
            <div>
              <input class="btn btn-primary" type="submit" value="保存"/> | <a @click="lbox.closeMyBoxLayer()" class="btn btn-danger" href="javascript:">返回</a>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</template>
<script type="text/javascript">
import '@/assets/css/style.css'

import $ from '@/assets/js/jquery-vendor.js'
import 'jquery.cookie'
import axios from 'axios'
import '@/assets/js/validate/validation-vendor.js'

import {apiUtil, axiosContentType, site} from '@/assets/js/boss'

export default {
  data() {
    return {
      item: {},
      newFlag: 0,
      uuidToken: ''
    }
  },
  mounted() {
    let that = window.$vueApp = this;
    document.getElementsByTagName('body')[0].className = 'fixed-sidebar full-height-layout';
    $('#examineResultForm').validate();
    that.staff.init(function () {
      that.newFlag = sessionStorage.getItem(site.examineResult.info);
      if (that.newFlag) that.uuidToken = apiUtil.guid();
      if (apiUtil.existSessionKey(site.examineResult.info)) {
        that.info();
      }
    });
  },
  methods: {
    info() {
      let that = this;
      axios.get(site.examineResult.info + sessionStorage.getItem(site.examineResult.info), {}).then(function (response) {
        const result = response.data;
        if (result.code === 0) {
          that.item = result.data;
        } else {
          alert(result.message);
        }
      });
    },
    save() {
      let that = this;
      if ($('#examineResultForm').valid()) {
        axios.post(site.examineResult.save, $('#examineResultForm').serialize(),
            axiosContentType.xWwwFormUrlencoded).then(function (response) {
          const result = response.data;
          // console.info("获取数据.." + JSON.stringify(result));
          if (result.code === 0) {
            parent.$vueApp.page();
            alert('保存成功!');
            that.lbox.closeMyBoxLayer()
          } else {
            alert(result.message);
          }
        });
      }
    }
  }
}
</script>

